import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MathExercisesPicker {
    private static final String INPUT_FILE = "MathExercises.csv";
    private static final String OUTPUT_FILE = "SelectedExercises.csv";
    private static final int EXERCISES_TO_PICK = 10;

    public static void main(String[] args) {
        List<String> allExercises = new ArrayList<>();
        List<String> selectedExercises = new ArrayList<>();

        // 读取所有的习题
        try (BufferedReader reader = new BufferedReader(new FileReader(INPUT_FILE))) {
            String line;
            while ((line = reader.readLine()) != null) {
                allExercises.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 随机选择10个不重复的习题
        Random random = new Random();
        while (selectedExercises.size() < EXERCISES_TO_PICK && !allExercises.isEmpty()) {
            int index = random.nextInt(allExercises.size());
            String exercise = allExercises.remove(index);
            selectedExercises.add(exercise.split(",")[0] + ","); // 只添加表达式
        }

        // 将选中的习题写入文件
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE))) {
            writer.write("Expression,Result\n"); // 写入标题行

            for (String exercise : selectedExercises) {
                writer.write(exercise + "\n"); // 写入表达式和空的Result列
            }
            System.out.println("Selected exercises have been written to " + OUTPUT_FILE);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}